package com.example.demo.service;

import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

/**
 * BPMN代理服务示例：自动发送通知
 * 这个服务任务会在流程执行时自动被调用
 */
@Component
public class NotificationService implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) {
        // 获取流程变量
        String employee = (String) execution.getVariable("employee");
        Boolean approved = (Boolean) execution.getVariable("approved");
        String reason = (String) execution.getVariable("reason");
        Integer days = (Integer) execution.getVariable("days");
        
        // 模拟发送通知逻辑
        String message = String.format(
            "员工 %s 的请假申请已处理完毕。\n" +
            "请假原因：%s\n" +
            "请假天数：%d天\n" +
            "审批结果：%s",
            employee, reason, days, approved ? "批准" : "拒绝"
        );
        
        System.out.println("=== BPMN代理服务执行 ===");
        System.out.println("发送通知：" + message);
        System.out.println("流程实例ID：" + execution.getProcessInstanceId());
        System.out.println("========================");
        
        // 这里可以集成实际的通知服务，如邮件、短信、钉钉等
        // emailService.sendNotification(employee, message);
    }
}
